//#pragma target 3.0

// note: TEXUNIT specifiers not needed?
void convolve(
        in float2 coord : TEXCOORD0,
        uniform int d_csize,
        uniform samplerRECT d_cFunc : TEXUNIT0,
        uniform int d_size,
        uniform samplerRECT d_data : TEXUNIT1,
        out float4 output : COLOR)
{
    const float x = coord.x - 0.5f;
    const float y = coord.y - 0.5f;
    const int cCentre = floor((float)d_csize / 2.0f);

    output = float4(0.0f, 0.0f, 0.0f, 0.0f);

//    output.r = texRECT(d_data, float2(x, y)).r;
//    output.r = cCentre;
//    output.r = x + cCentre;

    for (int iy = 0; iy < d_csize; ++iy)
    {
        for (int ix = 0; ix < d_csize; ++ix)
        {
            const int datax = x - ix + cCentre;
            const int datay = y - iy + cCentre;
            const float data = texRECT(d_data, float2(datax, datay)).r;

            const float4 conv = texRECT(d_cFunc, float2(ix, iy));

            output.r += data * conv.r;
            output.g += data * conv.g;
            output.b += data * conv.b;
            output.a += data * conv.a;
        }
    }
}
